<template>
	<div id="app">
		<!-- <div id="nav">
			<router-link to="/"></router-link>
		</div> -->
		<router-view />
	</div>
</template>

<script>
import { sendWebsocket, closeWebsocket } from "@/utils/websocket.js";
export default {
	name: 'App',
	mounted() {
		let root = document.getElementsByTagName('html')
		if (root.length > 0) {
			//debugger
			const winWide = window.screen.width
			let fz = (winWide / 1920) * 100 + 'px'
			root[0].style.cssText = 'font-size:' + fz
		}
		window.addEventListener("load", () => {
     this.requstWs()
    });
		
	},
	computed: {
   
    userid(){
      return this.$store.getters.user
    },
  },
  beforeDestroy(){
    console.log('清除')
    closeWebsocket();
  },
	methods: {
		requstWs() {
			// 防止用户多次连续点击发起请求，所以要先关闭上次的ws请求。
			closeWebsocket();
			// 跟后端协商，需要什么参数数据给后台
			// const obj = {
      

			//   monitorUrl: "xxxxxxxxxxxxx",
			//   userName: "xxxxxxxxxx",
			// };
			// 发起ws请求
      //let wssurl = process.env.VUE_APP_ENV === 'production' ? `wss://${process.env.VUE_APP_API_URL}` : `ws://${window.document.location.host}`
      let head = (location.protocol === 'https:') ? 'wss://' : 'ws://';
      let wssurl = head + window.document.location.host;
			if (this.$store.getters.user) {
				sendWebsocket(`${wssurl}${this.$API.websocket}${this.$store.getters.user.id}`, '', this.wsMessage, this.wsError);
			}
		},
		
	},
	watch: {
   
    userid(value) {
			this.requstWs()
    },
  },
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
#app
  -webkit-font-smoothing: antialiased
  -moz-osx-font-smoothing: grayscale
</style>
<style lang="stylus">
.el-menu--popup{
  min-width: 2rem !important;
  padding:0px !important;
}
</style>
